<template>
    <el-row>
      <el-card class="box-card">
        <el-table
            class="table"
            :data="tableData"
            style="width: 100%;">

          <el-table-column
              fixed
              type="index"
              label="序号"
              width="100">
          </el-table-column>

          <el-table-column
              prop="orderNumber"
              label="订单号"
              width="250">
          </el-table-column>

          <el-table-column
              prop="orderName"
              label="收货人"
              width="185">
          </el-table-column>

          <el-table-column
              prop="orderPhone"
              label="手机号"
              width="420">
          </el-table-column>

          <el-table-column
              prop="orderAddress"
              label="收货地址"
              width="540">
          </el-table-column>

          <el-table-column
              prop="orderCreateTime"
              label="创建时间"
              width="200">
          </el-table-column>


          <el-table-column
              prop="orderState"
              label="订单状态"
              width="140">
            <template slot-scope="scope">
              <span style="margin-left: 10px"> {{ stat(scope.row.orderState) }}</span>
            </template>
          </el-table-column>

        </el-table>
      </el-card>
    </el-row>

</template>
<script>
import Header from "../../components/Header";
import router from "../../router";

export default {
  name: "Order",
  components: { Header },
  data() {
    return {
      tableData: []
    }
  },
  methods: {
    checkLogin() {
      if (sessionStorage.getItem("isLogin") === "false") {
        this.$message.error("请先登录")
        router.push("/main")
      }
    },
    getOrder() {
      this.$axios.get("/order/get", {params: {"order_user_id": sessionStorage.getItem("user_id")}}).then(res => {
        console.log(res.data.data)
        this.tableData = res.data.data
      })
    },
    stat(state) {
      let text = {
        0:"已支付",
        1:"未支付",
        2:"已取消",
        3:"已退款",
        4:"待退款"
      }
      return text[state]
    }
  },
  created() {
    this.checkLogin()
    this.getOrder()

  }
}
</script>

<style scoped>
  .table {
  }
</style>